
/**
 * 防抖函数
 * @param func 
 * @param wait 
 * @returns 
 */
export const debounce = <T extends (...args: any[]) => any>(func: T, wait: number = 200): (...args: Parameters<T>) => void => {
    let timeout: NodeJS.Timeout | undefined;
    return function (this: ThisParameterType<T>, ...args: Parameters<T>): void {
        const context = this;
        clearTimeout(timeout);
        timeout = setTimeout(() => {
            func.apply(context, args);
            timeout = undefined;
        }, wait);
    };
}